package peer.rdp.message;


import java.net.DatagramPacket;

import peer.Message;
import peer.rdp.Connection;
import peer.tools.ByteIntSwitch;
import peer.tools.ByteShortSwitch;




public class AskFillMessage extends Message{

	int sequence=0;
	byte[] dpData=new byte[8];
	Connection conn;
	public long creatTime=0;
	public AskFillMessage(Connection conn,int sequence){
		this.conn=conn;
		this.sequence=sequence;
		sType=peer.tools.MessageType.sType_AskFillMessage;
		ByteShortSwitch.toByteArray(ver, dpData, 0);  //add: ver
		ByteShortSwitch.toByteArray(sType, dpData, 2);  //add: service type
		ByteIntSwitch.toByteArray(sequence, dpData, 4);  //add: sequence
		dp=new DatagramPacket(dpData,dpData.length);
		creatTime=System.currentTimeMillis();
	}
	
	public AskFillMessage(DatagramPacket dp){
		this.dp=dp;
		dpData=dp.getData();
		ver=ByteShortSwitch.toShort(dpData, 0);
		sType=ByteShortSwitch.toShort(dpData, 2);
		sequence=ByteIntSwitch.toInt(dpData, 4);
	}
	
	public int getSequence(){
		return sequence;
	}
	
	long getCreatTime(){
		return creatTime;
	}
	
	public boolean equals(Object obj){
		ReSendMessage rm=(ReSendMessage)obj;
		if(creatTime==rm.creatTime&&sequence==rm.sequence){
			return true;
		}else{
			return false;
		}
	}
	
	
	public int hashCode(){
		return Long.toString(sequence).hashCode();
	}


}
